<?php
namespace app\index\controller;
use app\common\lib\Util;
use app\common\lib\Redis;
use app\common\lib\redis\Predis;
class Login
{
    /*
     * 登陆
     */
    public function index()
    {
        //phone code
        $phoneNum = intval($_GET['phone_num']);
        $code = intval($_GET['code']);
        if(empty($phoneNum) || empty($code)){
            return Util::show(-2,'手机号或者验证码不能为空');
        }
        //redis code
        $redisCode = Predis::getInstance()->get(Redis::smsKey($phoneNum));

        if($redisCode !=$code){
            return Util::show(-3,'验证码不正确，登陆失败');
        }else{
            $data=[
                'user'=>$phoneNum,
                'srcKey'=>md5(Redis::userKey($phoneNum)),
                'time'=>time(),
                'isLogin'=>true,
            ];
            Predis::getInstance()->set(Redis::userKey($phoneNum),$data);
            $rediscode=Predis::getInstance()->get(Redis::userKey($phoneNum),$data);
            if($rediscode){
                session("phone", $phoneNum);
            }

            return Util::show('1','sucess',$data);
        }

    }

}
